<?php 
/**
* @name Maiji
* @author pd87@qq.com
* @copyright m-j.cc
* @version v1.0
*/

/* 
	DB实例化数据库
 */
function db($bname = ''){
	if(empty($bname)){
		return new MAIJI\Model;
	}else{
		return new MAIJI\Model($bname);
	}
}

/* 
	取出验证码
 */
function vcode(){
	$vcode = new MAIJI\Vcode;
	$code = $vcode -> doimg();
	session('vcode',$vcode -> getCode());
	return $code;
}

/* 
	简化session的使用
 */
function session($val,$zhi=null,$time=0){
	$se = new MAIJI\session;
	if($zhi === null){
		if($time === -1){
			return $se -> set($val,$zhi);
		}else{
			return $se -> get($val);
		}
	}else{
		return $se -> set($val,$zhi,$time);
	}
}

/* 
	简化COOKIE的使用
 */
function cookies($val,$zhi=null,$time=0){
	$ck = new MAIJI\Cookies;
	if($zhi === null){
		return $ck -> get($val);
	}else{
		return $ck -> set($val,$zhi,$time);
	}
}

/* 
	缓存方法
 */
function S($val,$zhi=null,$time=30000){
	$cache = new MAIJI\cache;
	if($zhi === null){
		return $cache -> get($val);
	}else{
		return $cache -> set($val,$zhi,$time);
	}
}

/* 
	接收数据
 */
function I($val = null){
	if($val == null){
		return null;
	}else{
		$_ls = explode('.',$val);
		if(count($_ls) > 1){
			$val = $_ls[0];
			$name = $_ls[1];
			if($val == 'post'){				
				if(isset($GLOBALS['_POST'][$name])){
					$value = $GLOBALS['_POST'][$name];
					return $value;
				}else{
					return $GLOBALS['_POST'];
				}
			}elseif($val == 'get'){
				if(isset($GLOBALS['_GET'][$name])){
					$value = $GLOBALS['_GET'][$name];
					return $value;
				}else{
					return $GLOBALS['_GET'];
				}
			}
		}else{
			if($val == 'post'){
				return $GLOBALS['_POST'];
			}elseif($val == 'get'){
				return $GLOBALS['_GET'];
			}
		}
	}
}
